package cn.imnaer.service.rpc.recommendcircle.impl;

import java.util.ArrayList;
import java.util.List;

import cn.imnaer.service.persistence.model.Recommend;
import cn.imnaer.service.persistence.model.Scenic;
import cn.imnaer.service.rest.view.model.RecommendView;
import cn.imnaer.service.rpc.collect.application.CollectComponentRpcApiImpl;
import cn.imnaer.service.rpc.common.CommonRpcApiImpl;
import cn.imnaer.service.rpc.recommend.dao.RecommendDaoImpl;
import cn.imnaer.service.rpc.recommendcircle.RecommendComponentRpcApi;
import cn.imnaer.service.rpc.scenic.dao.ScenicDaoImpl;
import cn.imnaer.service.rpc.scenic.process.ScenicCommentService;

public class RecommendComponentRpcApiImpl extends CommonRpcApiImpl implements RecommendComponentRpcApi {
	private ScenicCommentService scenicCommentService=new ScenicCommentService();

	@Override
	public List<RecommendView> getRecommendList(int page) {
		List<Recommend> recommendList = RecommendDaoImpl.getInstance().getPerPage(page);
		List<RecommendView> recommendViewList = RecommendView.valueOfList(recommendList);
		for (RecommendView recommendView : recommendViewList) {
			String type = recommendView.getRecommendType();
			if("SCENIC".equals(type)){
			String scenicId = recommendView.getRecommendId();
			Scenic scenic=	ScenicDaoImpl.getInstance().findOneByPk(scenicId);
			if(scenic!=null){
				 recommendView.setRecommendId(scenic.getScenicId());
				 recommendView.setName(scenic.getScenicName());
				 recommendView.setImage(scenic.getImages());
				 recommendView.setCollectCount(scenic.getCollectCount());
				 recommendView.setScenicType(scenic.getType());
				 recommendView.setType0("公交直达");
				 recommendView.setType1(scenic.getCommentCount()+"条评论");
				 recommendView.setType2(scenic.getCity().getCityName());
			recommendView.setAvatar(scenicCommentService.getFirstCommentUserId(scenicId));
			}
			else{
				recommendView.setRecommendId(null);
			}
			}
		}
		return recommendViewList;
	}
}
